package com.zklh.leetcode.other.problem1;

/**
 * @ClassName MergeTwoList
 * @Description
 * @Author 坐看落花
 * @Date 2019/7/18 20:59
 * @Version 1.0
 **/
public class MergeTwoList {
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode headNode = new ListNode(0);
        ListNode nowNode = headNode;
        while(l1 != null && l2 != null){
            nowNode.next = new ListNode(0);
            nowNode = nowNode.next;
            if(l1.val <= l2.val){
                nowNode.val = l1.val;
                l1 = l1.next;
            }else{
                nowNode.val = l2.val;
                l2 = l2.next;
            }
        }
        while(l1 == null){
            nowNode.next = new ListNode(l1.val);
            l1 = l1.next;
            nowNode = nowNode.next;
        }
        while(l2 == null){
            nowNode.next = new ListNode(l2.val);
            l2 = l2.next;
            nowNode = nowNode.next;
        }
        return headNode.next;
    }
    public static void main(String[] args){
        MergeTwoList mergeTwoList = new MergeTwoList();
    }
}
